import { createApp, reactive, getCurrentInstance } from 'vue';
const extend = Object.assign;
export function usePopupState() {
    const state = reactive({
        show: false,
    });
    const toggle = (show) => {
        state.show = show;
    };
    const open = (props) => {
        extend(state, props);
        toggle(true);
    };
    const close = () => toggle(false);
    const instance = getCurrentInstance();
    if (instance) {
        extend(instance.proxy, { open, close, toggle });
    }
    return {
        open,
        close,
        state,
        toggle,
    };
}
export function mountComponent(RootComponent) {
    const inBrowser = typeof window !== 'undefined';
    if (!inBrowser)
        return { instance: null, unmount() { } };
    const app = createApp(RootComponent);
    const root = document.createElement('div');
    root.style.position = 'relative';
    root.style.zIndex = '99999';
    document.body.appendChild(root);
    return {
        instance: app.mount(root),
        unmount() {
            app.unmount();
            document.body.removeChild(root);
        },
    };
}
